﻿Imports Oracle.DataAccess.Client
Public Class fListaConsec
    Private lIDConsec As String
    Public ReadOnly Property Consec() As String
        Get
            Return lIDConsec
        End Get
    End Property

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        Dim qWhere As String = ""
        If Me.txtConsec.Text.Trim.Length > 0 Then
            qWhere = "WHERE DESCRIPCION LIKE '%" & Me.txtConsec.Text & "%'"
        End If
        cmd.CommandText = "SELECT * FROM GLO_CONSECUTIVO " & qWhere
        Try
            Conn.Open()
            DsGlobal.GLO_CONSECUTIVO.Rows.Clear()
            DsGlobal.GLO_CONSECUTIVO.Load(cmd.ExecuteReader)
            Conn.Close()
            GLO_CONSECUTIVODataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub


    Private Sub GLO_CONSECUTIVODataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles GLO_CONSECUTIVODataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lIDConsec = GLO_CONSECUTIVODataGridView.Rows(e.RowIndex).Cells("IDCONSECUTIVO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaConsecutivo(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIDConsec = GLO_CONSECUTIVODataGridView.Rows(Fila).Cells("IDCONSECUTIVO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub


    Private Sub GLO_CONSECUTIVODataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GLO_CONSECUTIVODataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaConsecutivo(GLO_CONSECUTIVODataGridView.CurrentRow.Index)
        End If
    End Sub
End Class